package insulinpumpsimulation.com.his.model;

import insulinpumpsimulation.SimulationController;
import insulinpumpsimulation.com.his.audiocontrol.SoundAlert;
import insulinpumpsimulation.com.his.literal.InsulinPumpLiterals;
import insulinpumpsimulation.com.his.tasks.DurationCalculator;

/**
 *
 * @author Sabahul
 */
public class BatteryManager {
    
    private static SoundAlert speak=null;
    private static String path;
    
    // This returns battery level to Timer
    public double getBatteryLevel() {
        
        double batteryLevel = InsulinPumpLiterals.BATTERY_LEVEL_MASTER - (DurationCalculator.getRunningDuration()*1000 /InsulinPumpLiterals.SIMULATION_INTERVAL) * InsulinPumpLiterals.BATTERY_REDUCTION_SCALE;

        if (batteryLevel < 0) {
            batteryLevel = 0;
        }

        if (batteryLevel < .10) {
            SimulationController.getInstance()
                    .setIns_Msg_Area("The battery level is below 10 %. Please recharge the battery.");
          path="resources/resources/BatteryLevel_LOW.wav";     
          speak=new SoundAlert(path);
          speak.start();
          speak.stop();
        }

        return batteryLevel;
    }
}
